package com.example.demo.controller;


import com.example.demo.model.CustomResult;
import com.example.demo.model.PeopleConfig;
import com.example.demo.service.IPeopleConfigService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 人员配置 前端控制器
 * </p>
 *
 * @author chanchaw
 * @since 2021年6月14日
 */
@RestController
@RequestMapping("/peopleConfig")
public class PeopleConfigController {

    @Autowired
    private IPeopleConfigService peopleConfigService;

    @GetMapping("/info")
    public CustomResult<PeopleConfig> getInfo() {
        List<PeopleConfig> list = peopleConfigService.list();
        return CustomResult.Ok(list);
    }

    // @RequestBody 注解使用 Map 或者 PeopleConfig 都会报错


    // @RequestParam 逐个属性接收没问题，只是太麻烦//    @PostMapping("/save")
    ////    public CustomResult<PeopleConfig> save(@RequestBody Map<String,String> params){
    ////        System.out.println(params.toString());
    ////        return CustomResult.Ok(params.toString());
    ////    }
//    @PostMapping("/save")
//    public CustomResult<PeopleConfig> save(@RequestParam(value="tenantId") String tenantId,
//                                           @RequestParam(value="Empl_Id") String empl_Id,
//                                           @RequestParam(value="Name") String name){
//        String params = tenantId + "," + empl_Id + "," + name;
//        System.out.println(params);
//        return CustomResult.Ok(params);
//    }

    //@RequestParam 接收 Map 类型成功
//    @PostMapping("/save")
//    public CustomResult<PeopleConfig> save(@RequestParam Map<String,String> params){
//        String paramString = params.toString();
//        System.out.println(paramString);
//        return CustomResult.Ok(paramString);
//    }

    @PostMapping("/save")
    public CustomResult<PeopleConfig> save(PeopleConfig record){
        String paramString = record.toString();
        System.out.println("传入参数：" + paramString);
        Boolean ret = peopleConfigService.saveOrUpdate(record);
        System.out.println("保存后参数是：" + paramString);
        return CustomResult.Ok(peopleConfigService.getById(record.getId()));
    }
}
